package com.jqr.activity.recyclerviewdemo.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jqr.activity.recyclerviewdemo.R;


import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {

    private List<String> stringList;

    private Context context;


    private LayoutInflater layoutInflater;

    public MyAdapter(Context context,List<String> stringList){

        this.context=context;
        this.stringList=stringList;
        layoutInflater=LayoutInflater.from(context);

    }


    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= layoutInflater.inflate(R.layout.rv_list,parent,false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        String string =stringList.get(position);
        holder.tvString.setText(string);

    }

    @Override
    public int getItemCount() {
        return stringList.size();
    }

    static class MyHolder extends RecyclerView.ViewHolder{
       private TextView tvString;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            tvString=itemView.findViewById(R.id.tvString);
        }
    }
}
